package net.anzix.jhacks.flexclipse.editors;

import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;

public class MXMLEditor extends TextEditor {

	private ColorManager colorManager;

	private MXMLContentOutlinePage contentOutlinePage;
	
	public MXMLEditor() {
		super();
		colorManager = new ColorManager();
		setSourceViewerConfiguration(new XMLConfiguration(colorManager));
		setDocumentProvider(new XMLDocumentProvider());
	}
	public void dispose() {
		colorManager.dispose();
		super.dispose();
	}
	
	@Override
	public Object getAdapter(@SuppressWarnings("unchecked") Class adapter) {
		if(IContentOutlinePage.class.equals(adapter)) {
			return getOutlinePage();
		}
		return super.getAdapter(adapter);
	}

	/**
	 * Init and return the content outline page.
	 * @return
	 */
	private Object getOutlinePage() {
		if(contentOutlinePage == null){
			contentOutlinePage = new MXMLContentOutlinePage();
		}
		return contentOutlinePage;
	}

}
